﻿// Implements a field with a label content
define([
    'Wjs/ui/widgets/foundation/ViewHashContainer',
    'Wjs/ui/widgets/foundation/Label',
    'Wjs/ui/widgets/fields/TextField'
],
function () {
    'use strict';

    return Wjs.defineOnce({

        type: 'LabeledField',

        internal: {

            base: Wjs.getType('ViewHashContainer'),

            initialize: function () {

                this.addClass('wjs-labeled-field wjs-flex-row-container');
            },
        },

        setLabel: function (label) {

            label.setWidth('50%');

            if (this.getSection('label')) {

                this.replaceSection('label', label);
            }
            else {

                this.addSection('label', label);
            }

            return this;
        },

        getLabel: function () {

            return this.getSection('label');
        },

        setTextLabel: function (text) {

            return this.setLabel(

                Wjs.new('Label').setText(text)
            );
        },

        setHtmlLabel: function (html) {

            return this.setLabel(

                Wjs.new('Label').setHtml(html)
            );
        },

        setField: function (field) {

            field.addClass('wjs-display-flex-1');

            if (this.getSection('field')) {

                this.replaceSection('field', field);
            }
            else {

                this.addSection('field', field);
            }

            return this;
        },

        getField: function () {

            return this.getSection('field');
        }
    });

});